/**
 * Copyright 2020 Inc.
 **/
package com.myz.cloud.stream.rocketmq.consumer.stream;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * 对消息通道（Channel）的绑定@EnableBinding
 * 设置监听通道@StreamListener
 * 配合@StreamListener使用，在收到信息后发送反馈信息@SendTo
 *
 * @author maoyz0621 on 2020/8/17
 * @version v1.0
 */
@Component
@EnableBinding({StreamInputChannel.class, StreamOutputChannel.class})
@Slf4j
public class ReceiveClient {

    /**
     * 监听binding中的消息 @StreamListener
     *
     * @param message
     */
    @StreamListener(value = StreamInputChannel.INPUT)
    // @SendTo
    public void receive(Message message) {
        log.info("input = {}", message.getPayload());
    }

    /**
     * 接收headers条件参数
     *
     * @param message
     */
    @StreamListener(value = StreamInputChannel.BIND_receiver, condition = "headers['type']=='bar'")
    public void bind(Message message) {
        log.info("bind = {}", message.getPayload());
    }

    @StreamListener(value = StreamInputChannel.PUSH_receiver)
    public void push(Message message) {
        log.info("push = {}", message.getPayload());
    }
}